package flc.ast.adapter;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

import flc.ast.R;
import flc.ast.activity.IconActivity;
import flc.ast.bean.IconTypeBean;
import stark.common.api.StkApi;
import stark.common.api.StkResApi;
import stark.common.base.IReqRetCallback;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.view.container.StkRecycleView;
import stark.common.bean.StkResBean;

public class IconTypeAdapter extends StkProviderMultiAdapter<IconTypeBean> {

    public IconTypeAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(150));
        addItemProvider(new IconTypeProvider());
    }


    private class IconTypeProvider extends BaseItemProvider<IconTypeBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_icon_type;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, IconTypeBean bean) {
            baseViewHolder.setBackgroundColor(R.id.llIconTypeItem, Color.parseColor(bean.getColor()));
            baseViewHolder.setText(R.id.tvIconTypeItemName,bean.getName());
            StkRecycleView stkRecycleView=baseViewHolder.getView(R.id.rvIconTypeItemList);
            stkRecycleView.setLayoutManager(new GridLayoutManager(getContext(),4));
            IconTabAdapter iconTabAdapter=new IconTabAdapter();
            stkRecycleView.setAdapter(iconTabAdapter);
            iconTabAdapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                    getContext().startActivity(new Intent(getContext(),IconActivity.class));
                }
            });
            //获取数据
            StkResApi.getTagResourceList(null, bean.getUrl(), StkApi.createParamMap(0, 16), false,
                    new IReqRetCallback<List<StkResBean>>() {
                        @Override
                        public void onResult(boolean success, String msg, @Nullable List<StkResBean> result) {
                            if (success) {
                                if (result != null && result.size() > 0) {
                                    iconTabAdapter.setList(result);
                                }
                            }
                        }
                    });
        }
    }
}
